###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
#                           that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : CreateMainWindow
#
# Description : Create the main toplevel window
#
# Arguments :   None
#
# Returns :     Nothing
#
# Side-Effects :        None
#
# Exception Conditions :        None
#
# Pre-requisite Conditions :    None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
#                       update this segment of the file header block by
#                       adding a complete entry at the bottom of the list.
#
# Version     Date     Programmer   Comments / Changes / Reasons
# -------  ----------  ----------   -------------------------------------------
#       1  12/21/2009  G.Lester     Initial version
###########################################################################
proc CreateMainWindow {} {
    global apiList

    wm title . [::msgcat::mc Main.Title]
    set exitLabel [::msgcat::mc Main.Menu.File.Exit_Label]
    wm protocol . WM_DELETE_WINDOW [list .menu.file invoke $exitLabel]
    . configure -menu .menu

    ##
    ## Configure main menu (aka menu bar)
    ##
    menu .menu
    foreach item {File Help} {
        set menu [string tolower .menu.$item]
        menu $menu
        .menu add cascade \
            -label [::msgcat::mc Main.Menu.${item}_Label] \
            -underline [::msgcat::mc Main.Menu.${item}_Underline]  \
            -menu $menu
    }

    ##
    ## Configure the File Menu
    ##
    .menu.file add command \
        -command {destroy .} \
        -label $exitLabel \
        -underline [::msgcat::mc Main.Menu.File.Exit_Underline]

    ##
    ## Configure the Help Menu
    ##
    .menu.help add command \
        -command {DisplayHelp about} \
        -label [::msgcat::mc Main.Menu.Help.About_Label] \
        -underline [::msgcat::mc Main.Menu.Help.About_Underline]
    .menu.help add separator
    .menu.help add command \
        -command {DisplayHelp toc} \
        -label [::msgcat::mc Main.Menu.Help.TOC_Label] \
        -underline [::msgcat::mc Main.Menu.Help.TOC_Underline]

    ##
    ## Create a background body frame
    ##
    ::ttk::frame .body
    grid configure .body  -sticky nsew
    grid rowconfigure . .body -weight 1
    grid columnconfigure . .body -weight 1

    ##
    ## Create the notebook and its tabs
    ##
    ttk::notebook .body.nb
    foreach item $apiList {
        set text [::msgcat::mc Main.$item.Title]
        set underline [::msgcat::mc Main.$item.Title]
        set name [string tolower $item]
        set child [::ttk::frame .body.nb.$name]
        if {[string is integer -strict $underline]} {
            .body.nb add $child \
                -text $text \
                -underline $underline
        } else {
            .body.nb add $child \
                -text $text
        }
        CreateMainWindowTab $child $item
        bind $child <Visibility> [list VisibilityChange $child $item %s]
    }

    grid configure .body.nb  -sticky nsew
    grid rowconfigure .body .body.nb -weight 1
    grid columnconfigure .body .body.nb -weight 1

}

###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
#                           that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : CreateMainWindowTab
#
# Description : Create a tab on the main window
#
# Arguments :
#       w       - Window name of system tab
#       item    - Tab to create
#
# Returns :     Nothing
#
# Side-Effects :        None
#
# Exception Conditions :        None
#
# Pre-requisite Conditions :    None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
#                       update this segment of the file header block by
#                       adding a complete entry at the bottom of the list.
#
# Version     Date     Programmer   Comments / Changes / Reasons
# -------  ----------  ----------   -------------------------------------------
#       1  12/21/2009  G.Lester     Initial version
###########################################################################
proc CreateMainWindowTab {w item} {
    .body.nb tab $w -state disabled

    ::ttk::treeview $w.tree \
        -xscrollcommand [list $w.hsb set] \
        -yscrollcommand [list $w.vsb set] \
        -show {tree headings} \
        -columns {XmlTag Value} \
        -displaycolumns {Value} \
        -height 1
    ::ttk::scrollbar $w.hsb \
        -command [list $w.tree xview] \
        -orient horizontal
    ::ttk::scrollbar $w.vsb \
        -command [list $w.tree yview] \
        -orient vertical
    $w.tree heading #0 \
        -text [::msgcat::mc Main.Tab.Tree.Title]
    $w.tree heading Value \
        -text [::msgcat::mc Main.Tab.Value.Title]

    grid configure $w.tree $w.vsb -sticky nsew
    grid configure $w.hsb -sticky ew
    grid rowconfigure $w $w.tree -weight 1
    grid columnconfigure $w $w.tree -weight 1
}

###########################################################################
#
# Public Procedure Header - as this procedure is modified, please be sure
#                           that you update this header block. Thanks.
#
#>>BEGIN PUBLIC<<
#
# Procedure Name : VisibilityChange
#
# Description : Handle a visibility change on a tab
#
# Arguments :
#       w       - Window name of system tab
#       item    - Tab to create
#       state   - State of visibility
#
# Returns :     Nothing
#
# Side-Effects :        None
#
# Exception Conditions :        None
#
# Pre-requisite Conditions :    None
#
# Original Author : Gerald W. Lester
#
#>>END PUBLIC<<
#
# Maintenance History - as this file is modified, please be sure that you
#                       update this segment of the file header block by
#                       adding a complete entry at the bottom of the list.
#
# Version     Date     Programmer   Comments / Changes / Reasons
# -------  ----------  ----------   -------------------------------------------
#       1  12/21/2009  G.Lester     Initial version
###########################################################################
proc VisibilityChange {w item state} {
    if {[string equal $state VisibilityUnobscured]} {
        Populate${item}Tab $w
    }
}
